<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>OA办公管理系统-用户管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="cache-control" content="no-cache"/>
    <meta http-equiv="expires" content="0"/>
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"/>
    <meta http-equiv="description" content="This is my page"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/easyUI/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/publicStyle.css"/><!--分页样式  -->
</head>
<body style="overflow: hidden; width: 98%; height: 100%;">
<!-- 工具按钮区 -->
<form class="form-horizontal" action="" method="post" style="padding-left: 5px;">
    <table class="table-condensed">
        <tbody>
            <tr>
                <td style="padding-left: 0;"><input id="name" name="name" type="text" class="form-control" placeholder="姓名"></td>
                <td><input id="phone" type="text" name="phone" class="form-control" placeholder="手机号码"></td>
                <td>
                    <button type="button" id="selectUser" class="btn btn-info  operas" onclick="selUserList(1)"><span class="glyphicon glyphicon-search"></span>&nbsp;查询</button>
                    <a id="addUser" class="btn btn-success operas"><span class="glyphicon glyphicon-plus"></span>&nbsp;添加</a>
                </td>
            </tr>
        </tbody>
    </table>
</form>
<div class="panel panel-primary" style="padding-left: 5px;">
    <div class="panel-heading" style="background-color: #11a9e2;">
        <label>用户信息列表</label>
    </div>
    <div class="panel-body">
        <table class="table table-bordered table-hover" style="margin-bottom: 0;">
            <thead>
            <tr style="font-size: 12px;color: #333;" align="center">
                <th style="text-align: center;">账户</th>
                <th style="text-align: center;">昵称</th>
                <th style="text-align: center;">性别</th>
                <th style="text-align: center;">手机号码</th>
                <th style="text-align: center;">邮箱</th>
                <th style="text-align: center;">操作</th>
            </tr>
            </thead>
            <tbody id="data_info" valign="middle"></tbody>
        </table>
    </div>
    <!--分页条-->
    <div class="pager" id="pager"></div>
</div>

<div id="divDialog">
    <!-- 放置一个添加用户的界面  -->
    <iframe id="iframe" frameborder="0" style="width: 100%;height: 100%;"></iframe>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/jquery/jquery.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/jquery/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.myPagination.js"></script><!--分页  -->
<!-- 导入bootStrap的库 -->
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/layer/2.4/layer.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/plugins/layer/2.4/LayConstant.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        //分页
        selUserList(1);
    });


    //分页查询用户列表
    var pageSize = 5;
    function selUserList(pageNo) {
        var name = $("#name").val();
        var phone = $("#phone").val();
        var params = {"pageNo": pageNo, "pageSize": pageSize,"name":name,"phone":phone};
        var obj = $("#data_info");
        obj.empty();
        $.ajax({
            url: '${pageContext.request.contextPath}/user/selUserList.jspx',
            data: params,
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    var content = data.content[0].info, code = "";
                    var pageCount = data.content[0].pagetotal;//总页数
                    if (content.length < 1) {
                        layer.msg("暂无数据", {icon: 5, time: LayUIConstant.TIP_TIME});
                    } else {
                        for (var i = 0; i < content.length; i++) {
                            var userId = content[i].sysid;
                            code += '<tr id="user_' + i + '" align="center" style="cursor:pointer;color: #666;">' +
                                '<td>' + content[i].username + '</td>' +
                                '<td>' + content[i].likename + '</td>' +
                                '<td>' + (content[i].sex == 'M' ? '男' : '女') + '</td>' +
                                '<td>' + content[i].phone + '</td>' +
                                '<td>' + content[i].email + '</td>' +
                                '<td>' +
                                '<a id="updateUser" class="btn btn-success" onclick="updateUser(\'' + userId + '\')">修改</a> ' +
                                '<a id="preUser" class="btn btn-primary" onclick="preUser(\'' + userId + '\')">预览</a> ' +
                                '<a id="delUser" class="btn btn-danger" onclick="delUser(\'' + userId + '\')">删除</a> ' +
                                '</td>' +
                                '</tr>';
                        }
                        obj.append(code);
                        if (pageCount > 0) {
                            //分页
                            $("#pager").myPagination({
                                currPage: pageNo, //初始选择的页数
                                pageCount: pageCount,//总页数
                                pageSize: pageSize //显示多少页
                            });
                        }
                    }
                } else {
                    layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error: function () {
                layer.msg("系统错误!", {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }
    //为添加按钮绑定事件
    $("#addUser").click(function () {
        $('#divDialog').dialog({
            title: "添加用户", // 标题
            cls: "easyui-dialog", // class
            width: 600, // 宽度
            height: 350, // 高度
            maximizable: true, // 最大化
            minimizable: false, // 最小化
            collapsible: true, // 可伸缩
            modal: true, // 模态窗口
            onClose: function () { // 关闭窗口

                window.location = "${pageContext.request.contextPath}/user/selectUser.jspx";
            }
        });
        //通过iframe来引入一个添加用户的页面
        $("#iframe").attr("src", "${pageContext.request.contextPath}/user/showAddUser.jspx");

    })

    //修改用户信息
    function updateUser(userId) {
        $('#divDialog').dialog({
            title: "修改用户", // 标题
            cls: "easyui-dialog", // class
            width: 380, // 宽度
            height: 350, // 高度
            maximizable: true, // 最大化
            minimizable: false, // 最小化
            collapsible: true, // 可伸缩
            modal: true, // 模态窗口
            onClose: function () { // 关闭窗口
                window.location = "${pageContext.request.contextPath}/user/selectUser.jspx";
            }
        });
        //通过iframe来引入一个修改用户的页面
        $("#iframe").attr("src", "${pageContext.request.contextPath}/user/showUpdateUser.jspx?userId=" + userId);
    }

    //预览用户信息
    function preUser(userId) {
        $('#divDialog').dialog({
            title: "预览用户", // 标题
            cls: "easyui-dialog", // class
            width: 380, // 宽度
            height: 230, // 高度
            maximizable: true, // 最大化
            minimizable: false, // 最小化
            collapsible: true, // 可伸缩
            modal: true, // 模态窗口

        });
        //通过iframe来引入一个预览用户的页面
        $("#iframe").attr("src", "${pageContext.request.contextPath}/user/preUser.jspx?userId=" + userId);
    }

    //删除用户
    function delUser(userId) {
    	if(!confirm("是否删除选中的项？")){
            return;
        }
        $.ajax({
            url: '${pageContext.request.contextPath}/user/delUser.jspx',
            data: {"userId": userId},
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    layer.msg(data.message, {icon: 1, time: LayUIConstant.TIP_TIME}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error: function (data) {
                layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }

    function pageOnClick(page) {
        selUserList(page);
    }
    //分页文本框中直接输入时触发： properchange：适用IE9以及以上版本  onchange：IE不适用  两者必须有获取焦点失去焦点后才能触发
    function inputChange() {
        var pageNo = $('#pageInput').val();//文本框中当前页
        selUserList(pageNo);
    }
</script>


</body>

</html>